﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Test_QianBZ.Models;
using Test_QianBZ.Repository;

namespace Test_QianBZ.Domain
{
    public class EatlogDomain
    {
        public List<EatLogModel> GetLog(int personId)
        {
            return (new EatLogRepository()).GetLog(personId);
        }

        public int AddLog(EatLogModel food)
        {
            return (new EatLogRepository()).AddLog(food);
        }

        public List<EatDetailModel> GetLogWithName(int personId = 0)
        {
            return (new EatLogRepository()).GetLogWithName(personId);
        }

        public List<EatDetailModel> GetLastEat(int personId = 0)
        {
            var log = (new EatLogRepository()).GetLogWithName(personId).OrderByDescending(s => s.EatTime).GroupBy(s=>s.EatTime.Value.ToShortDateString());
            var res = new List<EatDetailModel>();
            foreach (var l in log)
            {
                res.Add(l.First());
            }
            return res;
        }

        public int DelEatLog(int LogId)
        {
            return (new EatLogRepository()).DelEatLog(LogId);
        }
    }
}
